// 数据库操作
const mongoose = require('mongoose');
// 对象规则验证
const Joi = require('joi');

const {
	Schema
} = mongoose;

// 定义后台菜单集合规则
const MenuModel = new Schema({
	_id: {
		type: Number,
		required: true
	},
	// 用户名称
	authName: {
		type: String,
		required: true
	},
	path: {
		type: String,
		required: true
	},
	children: [{
		_id: {
			type: Number,
			required: true
		},
		authName: {
			type: String,
			required: true
		},
		path: {
			type: String,
			required: true
		},
		children: [{
			type: String,
			default: null
		}],
		order: {
			type: Number,
			default: 0
		}
	}],
	order: {
		type: Number,
		default: 1
	}

}, {
	versionKey: false
});

// 菜单集合类
const Menu = mongoose.model('menu', MenuModel, 'menu');

// Menu.create({
// 	_id: 145,
// 	authName: "数据统计",
// 	path: "reports",
// 	children: [{
// 		_id: 146,
// 		authName: "数据报表",
// 		path: "reports",
// 		children: [],
// 		order: null
// 	}],
// 	order: 5
// })

// 导出对象
module.exports = {
	Menu
};
